<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>银行系统 - 贷款申请审批</title>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

.header {
    background-color: #333;
    color: white;
    padding: 20px;
    text-align: center;
}

.navbar {
    background-color: #444;
    overflow: hidden;
}

.navbar a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.navbar a:hover {
    background-color: #555;
}

.navbar a.active {
    background-color: #555;
}

.content {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.search-form {
    margin-bottom: 20px;
    padding: 10px;
    background-color: #f1f1f1;
    border-radius: 5px;
}

.search-form input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 300px;
}

.search-form button {
    background-color: #4CAF50;
    color: white;
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.loan-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.loan-table th, .loan-table td {
    border: 1px solid #ddd;
    padding: 12px 15px;
    text-align: left;
}

.loan-table th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.loan-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.loan-table tr:hover {
    background-color: #f5f5f5;
}

.status-pending { color: #FF9800; }
.status-approved { color: #4CAF50; }
.status-rejected { color: #F44336; }
.status-paid { color: #2196F3; }

.pagination {
    margin-top: 20px;
    text-align: center;
}

.pagination a {
    display: inline-block;
    padding: 8px 12px;
    text-decoration: none;
    color: #333;
    border: 1px solid #ddd;
    margin: 0 2px;
    border-radius: 4px;
}

.pagination a.active {
    background-color: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.pagination a:hover:not(.active) {
    background-color: #f1f1f1;
}

.error-message {
    color: #F44336;
    margin: 10px 0;
    padding: 10px;
    background-color: #ffcccc;
    border-radius: 4px;
}

.success-message {
    color: #4CAF50;
    margin: 10px 0;
    padding: 10px;
    background-color: #ccffcc;
    border-radius: 4px;
}
</style>
</head>
<body>
    <div class="header">
        <h1>银行管理系统 - 贷款申请审批</h1>
        <p>欢迎您，<c:out value="${sessionScope.user.username}" /></p>
    </div>
    
    <div class="navbar">
        <a href="totalUser">首页</a>
        <a href="adminLoanApplications" class="active">贷款审批</a>
        <a href="adminLoanHistory.jsp">贷款历史</a>
        <a href="account">账户管理</a>
        <a href="logout">退出登录</a>
    </div>
    
    <div class="content">
        <h2>待审批贷款申请</h2>
        
        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>
        
        <c:if test="${not empty success}">
            <div class="success-message">${success}</div>
        </c:if>
        
        
        <c:if test="${not empty loans}">
            <table class="loan-table">
                <tr>
                    <th>贷款ID</th>
                    <th>贷款编号</th>
                    <th>申请人</th>
                    <th>申请金额</th>
                    <th>申请时间</th>
                    <th>到期日</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${loans}" var="loans">
                    <tr>
                        <td>${loans.id}</td>
                        <td>${loans.loan_number}</td>
                        <td>${loans.user.real_name}</td>
                        <td>${loans.amount}</td>
                        <td>${loans.create_time}</td>
                        <td>${loans.due_date}</td>
                        <td>
						<a href="${pageContext.request.contextPath}/admin/loanDetail?id=${loans.id}">查看详情</a>                        
						</td>
                    </tr>
                </c:forEach>
            </table>
            
            <div class="pagination">
                <c:if test="${pageNum > 1}">
        		<a href="loanApplications?pageNum=${pageNum-1}&keyword=${keyword}&status=${param.status}" 
           			class="page-link">&laquo; 上一页</a>
    			</c:if>
                
                <c:forEach begin="1" end="${totalPages}" var="i">
                <a href="loanApplications?pageNum=${i}&keyword=${keyword}&status=${param.status}" 
                   class="page-link ${pageNum == i ? 'active' : ''}">${i}</a>
           		</c:forEach>
                
                <c:if test="${pageNum < totalPages}">
        		<a href="loanApplications?pageNum=${pageNum+1}&keyword=${param.keyword}&status=${param.status}" 
           			class="page-link">下一页 &raquo;</a>
    			</c:if>
            </div>
        </c:if>
    </div>
</body>
</html>